package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.service.WmUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author huan
 * @serial 每天一百行, 致敬未来的自己
 * @Description
 */


@RestController
@RequestMapping("/api/v1/user")
@Api(value = "自媒体用户管理", tags = "自媒体用户管理")
public class WmUserController {

    @Autowired
    private WmUserService userService;

    @PostMapping("/save")
    @ApiOperation("保存自媒体用户")
    public ResponseResult save(@RequestBody WmUser wmUser) {
        userService.save(wmUser);
        return ResponseResult.okResult(wmUser);
    }

    @GetMapping("/findByName/{name}")
    @ApiOperation("按照名称查询用户")
    public ResponseResult findByName(@PathVariable("name") String name) {
        WmUser wmUser = userService.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, name));
        return ResponseResult.okResult(wmUser);
    }
}